﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace SHomeWorkshop.LunarMind.Commands
{
    /// <summary>
    /// 新建文档命令。此命令总是可以运行的。
    /// </summary>
    public static class NewDocumentCommand
    {
        private static RoutedUICommand routedUICmd;//创建私有字段

        public static RoutedUICommand RoutedUICmd//创建只读静态属性
        {
            get { return routedUICmd; }
        }

        static NewDocumentCommand()//类型构造器
        {
            routedUICmd = new RoutedUICommand(
                "NewDocumentCommand", 
                "NewDocumentCommand",
                typeof(NewDocumentCommand),//创建RoutedUICommand对象
                new InputGestureCollection() 
                { 
                    new KeyGesture(Key.N,ModifierKeys.Control,"Ctrl+N")
                });

            cmdBinding.Command = routedUICmd;
            cmdBinding.CanExecute += new CanExecuteRoutedEventHandler(cmdBinding_CanExecute);
            cmdBinding.Executed += new ExecutedRoutedEventHandler(cmdBinding_Executed);
        }

        private static CommandBinding cmdBinding = new CommandBinding();

        public static CommandBinding CmdBinding
        {
            get { return cmdBinding; }
        }

        static void cmdBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(Globals.fullPathOfApp);
        }

        static void cmdBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;//新建文档，此命令总是有效。
        }
    }
}
